package com.zm.product.controller;

import com.zm.product.model.Product;
import com.zm.product.service.IProductTCCService;
import com.zm.product.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 判断并减库存
 */
@RestController
public class ProductController {
    @Autowired
    private ProductService productService;
    @RequestMapping("/db/{id}")
    @Transactional
    public Boolean reduceStock(@PathVariable Long id) {
        Boolean result=false;
        if (id!=null){
            result = productService.reduceStock(id);
        }
        return result;
    }
    //////////////////////////////////////////////////////
    @Autowired
    private IProductTCCService productTCCService;
    @RequestMapping("/dbTCC/{id}")
    @Transactional
    public Boolean reduceStockTCC(@PathVariable("id") Long id) {
        Boolean result=false;
        if (id!=null){
            result = productTCCService.reduceStock(id);
        }
        return result;
    }
}
